/*
** Copyright (C) 2011 Viens Yann
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "TabConfig.hpp"
#include "Singleton.hpp"
#include "Variables.hpp"

TabConfig::TabConfig(): ATab("Configuration", "./data/icons/config.png")
{
  _filters = Singleton<Filters>::instance();
  _detector = Singleton<ObjectDetector>::instance();

  _global = new QHBoxLayout;
  _left = new QVBoxLayout;

  _inverseCheckBox = new QCheckBox("Inverser la camera", this);
  connect(_inverseCheckBox, SIGNAL(stateChanged(int)), this, SLOT(invertChanged(int)));
  _left->addWidget(_inverseCheckBox);

  _head = new QRadioButton("Visage");
  if (detectorPath == DETECTORPATHHEAD)
    _head->setChecked(true);
  connect(_head, SIGNAL(clicked(bool)), this, SLOT(headSelected(bool)));
  _body = new QRadioButton("Tronc");
  if (detectorPath == DETECTORPATHBODY)
    _body->setChecked(true);
  connect(_body, SIGNAL(clicked(bool)), this, SLOT(bodySelected(bool)));

  _algo = new QVBoxLayout;

  _algo->addWidget(_head);
  _algo->addWidget(_body);

  _detection = new QGroupBox("Base de l'algorithme de detection");
  _detection->setLayout(_algo);
  _detection->setFixedSize(200, 100);

  _left->addWidget(_detection);


  _global->addLayout(_left);
  _global->addWidget(&_cameraDisplay);

  this->setLayout(_global);
}

TabConfig::~TabConfig()
{
  delete _inverseCheckBox;
  delete _left;
  delete _global;
}

void	TabConfig::headSelected(bool)
{
  _detector->loadDetector(DETECTORPATHHEAD);
}

void	TabConfig::bodySelected(bool)
{
  _detector->loadDetector(DETECTORPATHBODY);
}

AGame*	TabConfig::getAssociatedGame()
{
  return NULL;
}

void	TabConfig::startGame()
{
}

void	TabConfig::stopGame()
{
}

void	TabConfig::invertChanged(int isChecked)
{
  if (isChecked)
    {
      _filters->add("revert", &Filters::revert);
    }
  else
    {
      _filters->remove("revert");
    }
}
